package com.springboot.web.controller;

import com.springboot.web.common.CommonResult;
import com.springboot.web.entity.Film;
import com.springboot.web.service.FilmService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/film")
@Slf4j
public class FilmController {

    @Resource
    private FilmService filmService;

    @GetMapping
    public List<Film> queryAll () {
        return filmService.queryAll();
    }

    @GetMapping("{id}")
    public Film queryById (@PathVariable("id") Integer filmId) {
        return filmService.queryById(filmId);
    }

    @PostMapping
    public CommonResult addOne (@RequestBody Film film) {
        filmService.addOne(film);
        return new CommonResult<>(0,"success",null);
    }

    @PutMapping
    public CommonResult modify (@RequestBody Film film) {
        filmService.modify(film);
        return new CommonResult<>(0,"success",null);
    }

    @DeleteMapping
    public CommonResult deleteOne (@RequestParam("film_id") Integer id) {
        filmService.deleteOne(id);
        return new CommonResult<>(0,"success",null);
    }
}
